//#pragma once
#ifndef __RSA_H
#define __RSA_H

typedef struct {
	unsigned int modulus;
	unsigned int exponent;
}key_t;


const unsigned short p_q[256] = {
	0x64f9 ,0x2c0f ,0x86b3 ,0xe40b ,0xa8a9 ,0xb0b1 ,0x9bb7 ,0x45ad ,
	0xca69 ,0xb2c7 ,0xd021 ,0xe507 ,0x5297 ,0xccd1 ,0xec29 ,0x2b4b ,
	0xcae5 ,0x3001 ,0xb48b ,0x85fd ,0x3bb9 ,0xbea9 ,0xe017 ,0xaa39 ,
	0xc23f ,0xff2f ,0xb43d ,0xef9f ,0xada1 ,0xb5a3 ,0x405d ,0x32b7 ,
	0x8ee7 ,0xc8cf ,0xcc43 ,0xaf75 ,0xee63 ,0x26d5 ,0x9037 ,0x4a0f ,
	0x81b3 ,0xd70b ,0x22e5 ,0x7243 ,0x4cf3 ,0xa4d5 ,0x7ef7 ,0xf743 ,
	0x6e89 ,0xdae9 ,0x6bbd ,0x6b11 ,0x4c73 ,0xe4f5 ,0x4613 ,0xf4a3 ,
	0x568f ,0x2fab ,0x843b ,0xd7cb ,0xe357 ,0x6e3b ,0x99d7 ,0xf2db ,
	0xce51 ,0x9751 ,0xe053 ,0xaddb ,0xdc93 ,0x4d81 ,0x6697 ,0x61cd ,
	0x3ad5 ,0x91bd ,0x2beb ,0x6e77 ,0x4bbf ,0xf779 ,0xc7bb ,0x3c11 ,
	0x3d97 ,0xbf87 ,0xa1c3 ,0x668b ,0xa37b ,0xda29 ,0x283f ,0x413f ,
	0xf60b ,0x54c5 ,0xacd9 ,0x395b ,0x634f ,0x50d5 ,0x7a15 ,0x993d ,
	0xa987 ,0xff07 ,0x38d7 ,0x6857 ,0x8d79 ,0x76b7 ,0xd5c7 ,0xacf1 ,
	0x44ad ,0x98f5 ,0x900d ,0x5dc1 ,0xe791 ,0xa4ff ,0x3ea1 ,0xed37 ,
	0x766f ,0x3bd7 ,0xba07 ,0x64f9 ,0xc0bb ,0x7991 ,0x7baf ,0xc34f ,
	0x9749 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25f7 ,
};
const unsigned int e_arri[128] = {
	0x0169b307 ,0x028aa755 ,0x02652065 ,0x01ea76bd ,0x03505bf7 ,0x035463f7 ,0x01d0456f ,0x0134e027 ,
	0x03b97d9f ,0x01650f95 ,0x02dcc343 ,0x024b38eb ,0x03c70ded ,0x013dc861 ,0x018a3f51 ,0x02e8025f ,
	0x02d1f2af ,0x03b067bf ,0x03888df3 ,0x037c180f ,0x01a2f9cf ,0x0100447f ,0x03a0368d ,0x02ae04bf ,
	0x02ddf775 ,0x02ea94cb ,0x03d01809 ,0x02ae99f3 ,0x024719e7 ,0x02e3358b ,0x02336b9f ,0x026e3547 ,
	0x01c83815 ,0x0302dfd7 ,0x0288e629 ,0x033d5575 ,0x018b5db9 ,0x03a94b0f ,0x02302627 ,0x01c3494b ,
	0x0137278d ,0x02e1caad ,0x023f2c57 ,0x02891435 ,0x028f45a5 ,0x02f4136f ,0x035cdb99 ,0x02a6645b ,
	0x01247ce3 ,0x0346947d ,0x01b219a7 ,0x02488aff ,0x01d7c4db ,0x01cda755 ,0x036861eb ,0x01a4f2a1 ,
	0x0375bcab ,0x026f7fe5 ,0x032d9a51 ,0x0175d819 ,0x025866d9 ,0x0397f609 ,0x03db5abf ,0x03bd72df ,
	0x018e128d ,0x02906ed5 ,0x0391c0d9 ,0x03c6d88b ,0x03310e2b ,0x039f815b ,0x02925d21 ,0x037d8cc7 ,
	0x03b1ca93 ,0x026bd15f ,0x02f8c21d ,0x031f165d ,0x02b7639b ,0x030ca4b3 ,0x03237fbb ,0x0178e4eb ,
	0x0347ab29 ,0x029d6d4b ,0x0275c141 ,0x03e47351 ,0x0115e1f9 ,0x0335744f ,0x03c2be83 ,0x0204938b ,
	0x0336e9d1 ,0x02b423ff ,0x038d7b9b ,0x03be67a1 ,0x02f9dc2f ,0x015d0bc5 ,0x02c2ffb1 ,0x01fe72f5 ,
	0x03e2c5dd ,0x02c92a15 ,0x03932d6d ,0x029c7097 ,0x010ad25f ,0x03bcf827 ,0x01bc6a63 ,0x035c0141 ,
	0x010507df ,0x01366961 ,0x0110691b ,0x0140d185 ,0x037bf101 ,0x01c49e31 ,0x02fff569 ,0x026c0fd5 ,
	0x02229cd3 ,0x017dad27 ,0x0257c0a5 ,0x011abfb3 ,0x03d19e39 ,0x01571ca5 ,0x01039f4f ,0x01687e4d ,
	0x01a0d593 ,0x01b396e3 ,0x011ee2f5 ,0x010df7cd ,0x011c3213 ,0x01bbf617 ,0x03712747 ,0x035eeecb ,
};
extern int generate_rand(char *p, int len);
extern void rsa_gen_keys(key_t *pub, key_t *priv);
// extern void rsa_encrypt(key_t key, char *mw, int Length, int *cw);
extern void rsa_encrypt(key_t key, char *mw, int Length, unsigned int *cw);
extern void rsa_decrypt(key_t key, unsigned int *cw, int Length, char *mw);
extern int test_rsa(int len);

#endif

